package com.sun.aptmodule;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import com.sun.apt_annotation.AptAnnotation;
//import com.sun.apt_api.MyAptApi;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import dalvik.system.PathClassLoader;

@AptAnnotation(desc = "我是MainActivity 上面的注解")
public class MainActivity extends AppCompatActivity {

    @AptAnnotation(desc = "我是 onCreate 上面的注解")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        MyAptApi.init();
        try {
            Class<?> aClass = getClassLoader().loadClass("com.sun.apt_api.MyAptApi");
            Log.e("TAG", "onCreate: "+aClass );
//            aClass.init();
            Method method = aClass.getMethod("init");
            method.invoke(aClass.newInstance());
        } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException e) {
            e.printStackTrace();
        }
    }
}